<?php
/**
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       Cake.View.Pages
 * @since         CakePHP(tm) v 0.10.0.1076
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
?>
<script type="text/javascript">
  $(function() {
     $("#TicketFile").change(function (){
       var fileName = $(this).val();
       fileName=fileName.split('\\');
       fileName = fileName.pop();
       $(".ticket_attach_filename").html(fileName);
     });
  });
</script>
            <table width="100%">
                <tr valign="top">
                    <td width="750">
                        <div class="billing_top_messagies">
				<?php foreach($notifications as $notification)
				{
					$notification=$notification['Notification'];
					if($notification['type']=='red')
						$div_id='red_circle';
					else
						$div_id='grey_circle';
					echo '
					<div class="top_message_wrp">
					     <div class="top_message_head">
						 <div id="'.$div_id.'"></div>
						 <div class="top_message_title">'.$notification['title'].'</div>
						 <div class="top_message_date">'.date("d.m.Y H:i",$notification['time']).'</div>
					     </div>
					     <div class="top_message_content">
						 '.$notification['text'].'
					     </div>
					     <div class="top_message_grey_line"></div>
					 </div>
					';
				}
				?>
                            <div class="top_message_history_links">
				<?php echo $this->Html->link('История оповещений',array('controller'=>'notifications','action'=>'index'));?>
                                <!--<a href="#">Настройка оповещений</a>-->
                            </div>
                        </div>
                        <div class="billing_main_grey_line"></div>			
                        <div class="billing_arcticle_wrapper">
                            <div class="billing_arcticle_title">Заказы</div>
                            <div class="billing_arcticle_content">
                                <table>
                                    <tr>
                                        <td><div class="billign_orders_statuses">Всего активных заказов:  <?php echo $active_orders;?></div></td>
                                        <td><div class="billign_orders_statuses">из них требуют продления: <?php echo $need_pay_orders;?></div></td>
                                        <td><div class="billign_orders_statuses">Всего неактивных заказов: <?php echo $not_active_orders;?></div></td>
                                        <!--<td><div class="billign_orders_statuses">Замороженных заказов: 0</div></td>-->
                                    </tr>
                                </table>
                                <div class="billing_main_grey_line"></div>
                                <table width="750">
                                    <tr valign="top">
                                        <td width="50%">
                                            <div class="billing_radio_orders_wrp">
                                                <div class="billing_radio_orders_title">Радиохостинг</div>
                                                <div class="billing_radio_orders_list">
							<table width="100%">
							<?php
							$counter=0;
							foreach($orders as $order)
							{
								$order=$order['Order'];
								$now=time();
								$tarif_name=$order['tarif'];
								$tarif_name=str_replace("Radioheart","Rh",$tarif_name);
								$tarif_name=str_replace(" кбит/с","",$tarif_name);
								if($order['oplachenodo']<$now)
								{
								?>
								<tr class="redrow">
									<td>ID <?php echo $order['id'];?></td>
									<td><?php echo $order['cost'];?> $</td>
									<td><?php echo $tarif_name;?></td>
									<td>
										<?php
										if($order['oplachenodo']>0)
										{
											echo "до ".date("d.m.Y",$order['oplachenodo'])." ";
											//echo  $this->Html->link('Продлить', array('controller' => 'orders','action' => 'pay',$order['id']));
											echo  $this->Html->link('Продлить', array('controller' => 'orders','action' => 'index#'.$order['id']));
										}
										else
										{
											echo "<b>Не оплачен</b> ";
											//echo  $this->Html->link('Оплатить', array('controller' => 'orders','action' => 'pay',$order['id']));
											echo  $this->Html->link('Оплатить', array('controller' => 'orders','action' => 'index#'.$order['id']));
										}
										?>
									</td>
								    </tr>
								<?php
									if(($orders[$counter]['Order']['oplachenodo']<$now) and(@$orders[$counter+1]['Order']['oplachenodo']>=$now))
									{
								?>
										<tr>
										    <td colspan="4"><div class="top_message_grey_orders"></div></td>
										</tr>
								<?php
									}
								}
								else
								{
								?>
								<tr>
									<td>ID <?php echo $order['id'];?></td>
									<td><?php echo $order['cost'];?> $</td>
									<td><?php echo $tarif_name;?></td>
									<td>
										<?php echo "до ".date("d.m.Y",$order['oplachenodo'])." "; /*echo  $this->Html->link('Продлить', array('controller' => 'orders','action' => 'pay',$order['id']));*/echo  $this->Html->link('Продлить', array('controller' => 'orders','action' => 'index#'.$order['id'])); ?>
									</td>
								    </tr>
								<?php
								}
								$counter++;
							}
							?>
                                                    </table>
                                                </div>
                                            </div>
                                        </td>
                                        <td width="50%">
                                            <div class="billing_web_orders_wrp">
                                                <div class="billing_radio_orders_title">Виртуальный хостинг Extra</div>
                                                <div class="billing_web_orders_list">
							<table width="100%">
							<?php
							$counter=0;
							foreach($webhosting_orders as $webhosting_order)
							{
								$webhosting_order=$webhosting_order['Webhosting'];
								$now=time();
								if($webhosting_order['oplachenodo']<$now)
								{
								?>
								<tr class="redrow">
									<td>ID <?php echo $webhosting_order['id'];?></td>
									<td><?php echo $webhosting_order['cost'];?> $</td>
									<td><?php echo $webhosting_order['tarif'];?></td>
									<td>
										<?php
										if($webhosting_order['oplachenodo']>0)
										{
											echo "до ".date("d.m.Y",$webhosting_order['oplachenodo'])." ";
											echo  $this->Html->link('Продлить', array('controller' => 'orders','action' => 'index#'.$webhosting_order['id']));
											//echo  $this->Html->link('Продлить', array('controller' => 'webhosting','action' => 'pay',$webhosting_order['id']));
										}
										else
										{
											echo "<b>Не оплачен</b> ";
											echo  $this->Html->link('Продлить', array('controller' => 'orders','action' => 'index#'.$webhosting_order['id']));
											//echo  $this->Html->link('Оплатить', array('controller' => 'webhosting','action' => 'pay',$webhosting_order['id']));
										}
										?>
									</td>
								    </tr>
								<?php
									if(($webhosting_orders[$counter]['Webhosting']['oplachenodo']<$now) and(@$webhosting_orders[$counter+1]['Webhosting']['oplachenodo']>=$now))
									{
								?>
										<tr>
										    <td colspan="4"><div class="top_message_grey_orders"></div></td>
										</tr>
								<?php
									}
								}
								else
								{
								?>
								<tr>
									<td>ID <?php echo $webhosting_order['id'];?></td>
									<td><?php echo $webhosting_order['cost'];?> $</td>
									<td><?php echo $webhosting_order['tarif'];?></td>
									<td>
										<?php
										echo "до ".date("d.m.Y",$webhosting_order['oplachenodo'])." ";
										echo  $this->Html->link('Продлить', array('controller' => 'orders','action' => 'index#'.$webhosting_order['id']));
										//echo  $this->Html->link('Продлить', array('controller' => 'webhosting','action' => 'pay',$webhosting_order['id']));
										?>
									</td>
								    </tr>
								<?php
								}
								$counter++;
							}
							?>
                                                    </table>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="billing_article_notification">
                              Оплачивайте заказы своевременно. Помните, что на следующий день после окончания срока оплаты, заказ будет заблокирован,
                              а спустя три дня — удален. Если вы по какой-то причине не можете в нужный момент продлить заказ, оповестите нас тикетом.
                              Рекомендуем пользоваться автопродлением заказов: при наступлении срока система автоматически будет списывать деньги с
                              баланса. Включить автопродление для каждого заказа можно на странице заказов.
                            </div>
                            <div class="billing_article_links">
                                <?php echo  $this->Html->link('Перейти на страницу заказов', array('controller' => 'orders','action' => 'index'));?>
				<?php echo  $this->Html->link('Сделать новый заказ', array('controller' => 'orders','action' => 'neworder'));?>
                                <?php //echo  $this->Html->link('Сделать новый заказ на радиохостинг', array('controller' => 'orders','action' => 'add'));?>
				<?php //echo  $this->Html->link('Сделать новый заказ на виртуальный хостинг', array('controller' => 'webhosting','action' => 'add'));?>
                            </div>
                        </div>
                        <div class="billing_main_grey_line"></div>
                        <div class="billing_arcticle_wrapper">
                            <div class="billing_arcticle_title">Новости</div>
                            <div class="billing_arcticle_content">
                                <table>
                                    <tr valign="top">
					<?php
						$firstnews=$news[0]['wp_posts'];
						$secondnews=$news[1]['wp_posts'];
					?>
                                        <td width="50%">
                                            <div class="billing_news_wrapper">
                                                <div class="billing_news_title"><a href="<?php echo $firstnews['guid'];?>" target="_blank"><?php echo $firstnews['post_title'];?></a></div>
                                                <div class="billing_news_date"><?php echo $firstnews['post_date'];?></div>
                                                <div class="billing_news_content">
                                                    <?php
							$content=explode("<!--more-->",$firstnews['post_content']);
							echo $content[0];
						    ?>
                                                </div>
                                            </div>
                                        </td>
                                        <td width="50%" class="billing_news_second">
                                            <div class="billing_news_wrapper">
                                                <div class="billing_news_title"><a href="<?php echo $secondnews['guid'];?>" target="_blank"><?php echo $secondnews['post_title'];?></a></div>
                                                <div class="billing_news_date"><?php echo $secondnews['post_date'];?></div>
                                                <div class="billing_news_content">
                                                    <?php
							$content=explode("<!--more-->",$secondnews['post_content']);
							echo $content[0];
						    ?>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="billing_article_links">
                                <a href="http://radioheart.ru/category/news/">Все новости в архиве</a>
                            </div>
                        </div>
                        <div class="billing_main_grey_line"></div>
                        <div class="billing_arcticle_wrapper">
                            <div class="billing_arcticle_title">Тикеты</div>
                            <div class="billing_arcticle_content">
                                <div class="send_ticket_form_wrapper">
					<?php
					    echo $this->Form->create('Ticket',array('type' => 'file','action' => 'send'));
					    echo $this->Form->input('text', array('label' => false,'required' => 1));
					    echo $this->Form->input('orderid', array(
						    'options' => $ids,
						    'label'=>false,
						    'div' => array(
						    'class' => 'sendticketorderselect',
						)
						));
					    echo $this->Form->input('file', array(
						'type' => 'file',
						'label'=>false,
						'accept'=>'image/*',
						'div' => array(
						    'class' => 'attachfilediv',
						)
						
						));
					    echo '<div class="ticket_attach_filename">Файл не выбран</div>';
					    $options = array(
						'label' => 'Отправить тикет',
						'div' => array(
						    'class' => 'sendticketbtn',
						)
					    );
					    echo $this->Form->end($options);
					?>
                                </div>
                                <div class="billing_tickets_list_main_wrp">
					<?php
						foreach($tickets as $ticket)
						{
						    $ticket=$ticket['Ticket'];
						    $ticket_date=date("H:i d.m.Y",$ticket['time']);
						    if($ticket['back']==1)
						    {
							//$name='Служба поддержки';
							echo '<div class="billing_ticket_main_wrp_answer">';
							echo '<div class="billing_ticket_head_answer">'.$ticket_date.'  Служба поддержки</div>';
						    }
						    else
						    {
							$name=$user_login." (для заказа ID ".$ticket['orderid'].")";
							echo '<div class="billing_ticket_main_wrp">';
							echo '<div class="billing_ticket_head">'.$ticket_date.'  '.$name.'</div>';
						    }
						    echo '<div class="billing_ticket_content">';
						    echo '<pre><code>'.$ticket['text'].'</code></pre>';
						    if(strlen($ticket['file'])>2)
							echo "Вложение: ".$ticket['file'];
						    echo '</div>'; //close content div
						    echo '</div>'; //close wrp div
						}					
					?>
                                </div>
                            </div>
                            <div class="billing_article_links">
				<?php echo  $this->Html->link('Перейти на страницу тикетов', array('controller' => 'tickets','action' => 'index'));?>
                            </div>
                        </div>
                        <div class="billing_main_grey_line"></div>
                        <div class="billing_arcticle_content">
                            <table width="750">
                                <tr valign="top">
                                    <td width="50%">
                                        <div class="billing_arcticle_title">Приложения</div>
                                        <div class="billing_article_links">
					    <?php echo  $this->Html->link('Публичные страницы', array('controller' => 'publicpages','action' => 'index'));?>
					    <br />
					    <?php echo  $this->Html->link('Конструктор скриптов', array('controller' => 'orders','action' => 'constructor'));?>
					    <br />
					    <?php echo  $this->Html->link('Плееры', array('controller' => 'orders','action' => 'player'));?>
					    <br />
					    <?php echo  $this->Html->link('Виджеты', array('controller' => 'orders','action' => 'api'));?>
					    
                                        </div>
                                    </td>
                                    <td width="50%">
                                        <div class="billing_arcticle_title">Вам нравится Radioheart</div>
                                        <div class="billing_article_links">
					    <?php echo  $this->Html->link('Отправить отзыв', array('controller' => 'reviews','action' => 'index'));?>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>			
                    </td>
                    <td width="280">
                        <?php echo $this->element('sidebar',array(
                                'balance_value'=>$balance_value,
                                'balance_time'=>$balance_time,
                                'all_orders_cost'=>$all_orders_cost,
                                'need_money'=>$need_money,
                                'autocontinue_one_of'=>$autocontinue_one_of));?>
                    </td>
                </tr>
            </table>			
